<template>
  <div class="cesium-draw">
    <div id="cesium-drawer"></div>
    <div class="mouse-postion">{{ nowPostion.wgs84 }}</div>
    <div class="tool-box">
      <div class="slider-box-wrapper"><slider-box v-model:value="step" :min="1" :max="100" :step="1" /></div>
      <div class="slider-box-wrapper"><slider-bar v-model:value="curTime" :min="0" :max="timeDuration" :step="1" /></div>
      <a class="tools" @click="togglePlay" :title="playing ? '暂停' : '播放'">
        <PlayCircleOutlined v-if="!playing" />
        <PauseCircleOutlined v-if="playing" />
      </a>

      <!--<div class="select-box-wrapper"><select-box :options="commonMaterials" /></div>
      <div class="select-box-wrapper"><select-box :options="baseMaterials" /></div>
      <div class="select-box-wrapper"><select-box :options="proceduralTextures" /></div>
      <div class="select-box-wrapper"><select-box :options="miscMaterials" /></div>
      <div class="select-box-wrapper"><select-box :options="compositeMaterials" /></div>
      <div class="select-box-wrapper"><select-box :options="polylineMaterials" /></div> -->

      <!-- <div class="select-box-wrapper"><a-checkbox v-model:checked="shadows">shadows</a-checkbox></div> -->
      <!-- <div class="select-box-wrapper"><a-checkbox v-model:checked="softShadows">soft shadows</a-checkbox></div> -->
      <!-- <div class="select-box-wrapper"><a-checkbox v-model:checked="terrainShadows">terrain shadows</a-checkbox></div> -->
      <!-- <div class="select-box-wrapper"><a-checkbox v-model:checked="picking">选择</a-checkbox></div> -->
      <div id="menu">
        <!-- <p><button @click="onClick('play')">播放</button></p> -->
        <!-- <p><button @click="onClick('stop')">暂停</button></p> -->
      </div>
    </div>
  </div>
</template>

<script>
// http://earthsdk.com/v/last/Apps/Examples/?menu=true&url=./earth-heatmap-kriging.html
import { DownOutlined, EditOutlined } from '@ant-design/icons-vue';
import { PlayCircleOutlined, PauseCircleOutlined, PlayCircleFilled, PauseCircleFilled } from '@ant-design/icons-vue';
import { defineComponent, ref, watch } from 'vue';
import * as Cesium from '@cesium/Source/Cesium.js';
import MousePosition from '@functional/utils/mousePosition';
import selectBox from '@components/widgets/select-box';
import sliderBox from '@components/widgets/slider-box';
import sliderBar from '@components/widgets/slider-bar';

export default defineComponent({
  name: 'lineMaterial', // 线材质
  components: { PlayCircleOutlined, PauseCircleOutlined, DownOutlined, EditOutlined, sliderBox, sliderBar, selectBox },
  setup() {
    return {
      viewer: null,
      timer: 0,
      synchronizer: null
    };
  },
  data() {
    return {
      timeDuration: 1000,
      step: 1,
      curTime: 1,
      nowPostion: {},
      playing: true
    };
  },
  computed: {},
  watch: {},
  mounted() {
    this.initViewer();
  },
  beforeUnmount() {
    if (this.viewer) {
      this.viewer.destroy();
      this.viewer = null;
    }
  },
  methods: {
    togglePlay() {
      this.playing = !this.playing;
    },
    onViewerInited(viewer) {
      let vm = this;
      new MousePosition(viewer, pos => {
        vm.nowPostion = pos;
      });
    },
    initViewer() {
      let vm = this;
      Cesium.Ion.defaultAccessToken = $accessToken.default;
      let osm = new Cesium.ArcGisMapServerImageryProvider({
        // url: '//services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer'
        url: '//services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
        show: false,
      });
      var viewer = new Cesium.Viewer('cesium-drawer', {
        // imageryProvider: osm,
        contextOptions: {
          webgl: {
            alpha: true
          }
        },
        // shadows: true,
        animation: false,
        // baseLayerPicker: false,
        fullscreenButton: false,
        vrButton: false,
        homeButton: false,
        timeline: false,
        selectionIndicator: false,
        infoBox: false,
        // 注释时相当于使用默认地形，解开注释相当于使用全球地形
        terrainProvider: Cesium.createWorldTerrain(),
        shouldAnimate: true
      });

      //开启深度检测
      // viewer.scene.globe.depthTestAgainstTerrain = true;

      this.viewer = viewer;
      this.onViewerInited(viewer);
      Cesium.GroundPrimitive.initializeTerrainHeights().then(() => {
        vm.initEffects();
      });

      // this.viewer.flyTo(this.viewer.entities);
    },
    initEffects() {
      let vm = this;
      const viewer = this.viewer;
      const scene = viewer.scene;
    }
  }
});
</script>

<style scoped lang="less">
.cesium-draw {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: white;
  font-size: 14px;

  #cesium-drawer {
    width: 100%;
    height: 100%;
    overflow: hidden;
    :deep(.cesium-viewer-bottom) {
      display: none !important;
    }
  }

  .mouse-postion {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-size: 14px;
    padding: 8px 12px;
    line-height: 16px;
    color: white;
    z-index: 9999;
    background-color: rgba(40, 48, 60, 1);
    border-radius: 3px;
    opacity: 0.8;
  }
}

.tool-box {
  position: absolute;
  top: 70px;
  left: 10px;
  z-index: 9;

  .tools {
    // position: absolute;
    top: 57px;
    left: 7px;
    font-size: 1.5em;
    padding: 4px 14px;
    color: white;
    z-index: 9999;
    background-color: rgba(40, 48, 60, 1);
    border-radius: 5px;
    opacity: 0.6;
    transition: all 500ms;
    &:hover {
      opacity: 0.8;
    }
  }

  #menu {
    padding-top: 20px;
    button {
      background-color: rgba(0, 0, 0, 0.75);
      border-color: rgba(0, 0, 0, 0);
      cursor: pointer;
      transition: all 500ms;
      &:hover {
        opacity: 0.75;
      }
    }
  }

  .slider-box-wrapper {
    width: 18em;
    padding: 0 10px;
    background-color: rgba(0, 0, 0, 0.75);
    margin-bottom: 10px;
  }

  .select-box-wrapper {
    padding: 5px 15px;
    background-color: rgba(0, 0, 0, 0.75);
    margin-bottom: 10px;
    width: auto;
  }
}
</style>
